package com.project.server.operate;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.operate.TOperateAffair;
import com.project.server.service.operate.ITOperateAffairService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运营管理办事指南Controller
 *
 * @author project
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/server/affair")
public class TOperateAffairController extends BaseController {

    @Resource
    private ITOperateAffairService tOperateAffairService;

    /**
     * 查询运营管理办事指南列表
     */
    @PreAuthorize("@ss.hasPermi('server:affair:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOperateAffair tOperateAffair) {
        startPage();
        List<TOperateAffair> list = tOperateAffairService.selectTOperateAffairList(tOperateAffair);
        return getDataTable(list);
    }


    /**
     * 导出运营管理办事指南列表
     */
    @PreAuthorize("@ss.hasPermi('server:affair:export')")
    @Log(title = "运营管理办事指南", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TOperateAffair tOperateAffair) {
        List<TOperateAffair> list = tOperateAffairService.selectTOperateAffairDelTags(tOperateAffair);
        ExcelUtil<TOperateAffair> util = new ExcelUtil<TOperateAffair>(TOperateAffair.class);
        return util.exportExcel(list, "办事指引列表");
    }

    /**
     * 获取运营管理办事指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:affair:query')")
    @GetMapping(value = "/{affairId}")
    public AjaxResult getInfo(@PathVariable("affairId") Long affairId) {
        return AjaxResult.success(tOperateAffairService.selectTOperateAffairById(affairId));
    }

    /**
     * 新增运营管理办事指南
     */
    @PreAuthorize("@ss.hasPermi('server:affair:add')")
    @Log(title = "运营管理办事指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TOperateAffair tOperateAffair) {
        return toAjax(tOperateAffairService.insertTOperateAffair(tOperateAffair));
    }

    /**
     * 修改运营管理办事指南
     */
    @PreAuthorize("@ss.hasPermi('server:affair:edit')")
    @Log(title = "运营管理办事指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TOperateAffair tOperateAffair) {
        return toAjax(tOperateAffairService.updateTOperateAffair(tOperateAffair));
    }

    /**
     * 删除运营管理办事指南
     */
    @PreAuthorize("@ss.hasPermi('server:affair:remove')")
    @Log(title = "运营管理办事指南", businessType = BusinessType.DELETE)
    @DeleteMapping("/{affairIds}")
    public AjaxResult remove(@PathVariable Long[] affairIds) {
        return toAjax(tOperateAffairService.deleteTOperateAffairByIds(affairIds));
    }
}
